<?php if (!defined('THINK_PATH')) exit();?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="__PUBLIC__/css/common.css">
<link rel="stylesheet" href="__PUBLIC__/css/main.css">
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript"
	src="__PUBLIC__/js/colResizable-1.3.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>

<script type="text/javascript">
      $(function(){  
        $(".list_table").colResizable({
          liveDrag:true,
          gripInnerHtml:"<div class='grip'></div>", 
          draggingClass:"dragging", 
          minWidth:30
        }); 
        
      }); 
   </script>
<title>编辑首页</title>

<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=uu7qMGBqMYQbFMTdNhy65ZgM"></script>
<!--引用百度地图API-->
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
}

.iw_poi_title {
	color: #CC5522;
	font-size: 14px;
	font-weight: bold;
	overflow: hidden;
	padding-right: 13px;
	white-space: nowrap
}

.iw_poi_content {
	font: 12px arial, sans-serif;
	overflow: visible;
	padding-top: 4px;
	white-space: -moz-pre-wrap;
	word-wrap: break-word
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=uu7qMGBqMYQbFMTdNhy65ZgM"></script>

</head>
<body>
<!--
 登陆成功<?php echo ($_SESSION['user']['username']); ?>
 -->
<div id="forms" class="mt10">
<div class="box">
<div class="box_border">
<div class="box_center">
<form action="<?php echo U('/Home/homeEdit');?>" id="form"
	class="jqtransform" method="post" enctype="multipart/form-data">
<table>
	<tbody>
		<tr>
			<td>
			<table class="form_table pt15 pb15" width="100%" border="0"
				cellpadding="0" cellspacing="0">
				<tr>
					<td class="td_right">首页标题:</td>
					<td class=""><input type="text" name="title"
						value="<?php echo ($list["title"]); ?>" class="input-text lh30"
						size="40"> <input type="hidden" name="id"
						value="<?php echo ($list["id"]); ?>" class="input-text lh30"
						size="40"></td>
				</tr>
				<tr>
					<td class="td_right">首页图片:</td>
					<td><?php if(is_array($homeImage)): foreach($homeImage as $key=>$im): ?>
					<div style="position: relative; float: left; margin-right: 5px;"><!-- javascript:$(this).parent().remove(); -->
					<div
						style="cursor: pointer; font-size: 18px; font-weight: bold; text-align: center; width: 18px; height: 18px; background: #ccc; color: red; position: absolute; right: 0px; top: 0px;"
						onclick="del();$(this).parent().remove();delImg(<?php echo ($im["id"]); ?>);">×</div>
					<img
						alt="__PUBLIC__/Uploads/image/home/<?php echo ($im["image"]); ?>"
						src="__PUBLIC__/Uploads/image/home/<?php echo ($im["image"]); ?>"
						style="width: 100px;"></div>
						<?php endforeach; endif; ?> <a href="javascript:();"
						class="btn btn-success" onclick="addPic()">添加图片</a></td>
				</tr>
				<tr>
					<td class="td_right"></td>
					<td>
					<div id="picDiv" class="span12"></div>
					</td>
				</tr>
				<tr>
					<td class="td_right"></td>
					<td class="">
					<div id="test" style="color: red;"></div>
					</td>
				</tr>
				<tr>
					<td class="td_right">&nbsp;</td>
					<td class=""><input type="button" class="btn btn82 btn_save2"
						onclick="onSub1();" value="保存"> <!-- <input type="submit" name="button" class="btn btn82 btn_save2" value="保存">  -->
					<input type="reset" name="button" class="btn btn82 btn_res"
						value="重置"></td>
				</tr>
			</table>
			</td>
		</tr>
	</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
	    function addPic(){
			$('#picDiv').append('<div class="clearfix" style="position:relative;height:32px;"><input style="width:280px;position:static;" onchange="checkPic(this)" type="file" name="img[]"/><a href="javascript:();" onclick="javascript:$(this).parent().remove();">移除</a><span class="required picError"></span></div>');
		}
	    function delImg(id){
	    	$.post("<?php echo U('Home/delImg');?>",{ id : id},function(data){
	    	})
	    }
        function del()
        {
            if (confirm("确定要删除吗？" ))
            {
                return true ;
            }
            else
            {
                return false ;
            }
        }
		//提交前执行
		function onSub1(){
			var title = $("input[name='title']").val();
			var img = $("input[name='img[]']").val();
			//判断用户名不能为空
			if(title == ""){
				$("#test").html("标题不能为空!");
				return false;
			}else{
				$("#test").html("");
			}
			var image = 0;
			$("*[name='img[]']").each(function(index,item){
				var img_reg = /^$|^(([a-zA-Z0-9_]+):(\\.+))|([a-zA-Z0-9_]+)(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$/;
				var imgs = $(this).val().trim();
				if(!img_reg.test(imgs)){
					image = 1;
				}else{
					$("#test").html("");
				}
		    });
			if(image == 1){
				$("#test").html("图片格式错误!");
				return false;
			}else{
				$("#test").html("");
			}
			$("#form").submit();
		}


	 </script>

</body>
